<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html ng-app="LeaderboardApp">
<head>
<meta charset="UTF-8">
<title>Administración de Metas</title>
<link href="/Leaderboard/css/bootstrap.min.css" rel="stylesheet" type="text/css"/>
<link href="/Leaderboard/css/bootstrap-theme.min.css" rel="stylesheet" type="text/css"/>
<link href="/Leaderboard/css/bootstrap-spinner.css" rel="stylesheet" type="text/css"/>
<link href="/Leaderboard/css/datepicker3.css" rel="stylesheet" type="text/css"/>
<link href="/Leaderboard/css/select2.css" rel="stylesheet" type="text/css"/>
<link href="/Leaderboard/css/select2-bootstrap.css" rel="stylesheet" type="text/css"/>
<link href="/Leaderboard/css/styles.css" rel="stylesheet" type="text/css"/>

<script type="text/javascript" src="/Leaderboard/js/lib/bootstrap/jquery-1.11.1.min.js"></script>
<script type="text/javascript" src="/Leaderboard/js/lib/bootstrap/respond.min.js"></script>
<script type="text/javascript" src="/Leaderboard/js/lib/bootstrap/bootstrap.min.js"></script>
<script type="text/javascript" src="/Leaderboard/js/lib/bootstrap/bootstrap3-typeahead.js"></script>
<script type="text/javascript" src="/Leaderboard/js/lib/bootstrap/jquery.spinner.min.js"></script>


<!--[if lt IE 9]><script type="text/javascript" src="/Leaderboard/js/lib/angularjs/html5shiv-printshiv.min.js"></script><![endif]-->
<!--[if lt IE 8]><script type="text/javascript" src="/Leaderboard/js/lib/angularjs/json3.min.js"></script><![endif]-->

<script type="text/javascript" src="/Leaderboard/js/lib/select2.min.js"></script>
<script type="text/javascript" src="/Leaderboard/js/lib/angularjs/angularjs-1.2.16.min.js"></script>
<script type="text/javascript" src="/Leaderboard/js/controllers.init.js"></script>
<script type="text/javascript" src="/Leaderboard/js/controllers.admin.js"></script>
<script type="text/javascript" src="/Leaderboard/js/controllers.metas.js"></script>

<!--[if lte IE 8]>
<script type="text/javascript">
    $(document).ready(function() {
        angular.bootstrap(document);
    });
</script>
<![endif]-->
</head>
<body>
	<div ng-include="'/Leaderboard/include/header.html'"></div>
	
	<div class="container">
		<div ng-include="'/Leaderboard/include/changePassword.html'"></div>
	
		<div ng-controller="metasCtrl">
			<div ng-include="'/Leaderboard/include/messages.html'"></div>
			<div class="panel panel-primary">
				<div class="panel-heading"><h3 class="panel-title">Administraci&oacute;n de Metas</h3></div>
				<div class="panel-body panel-body-scrollable">
					<form role="form" class="form-horizontal">
						<div class="form-group">
							<label class="col-sm-3 control-label">Seleccionar sucursal</label>
							<div class="col-sm-6">
								<select ng-change="getBranchMetas()" ng-options="branch.name for branch in branches" ng-model="branch" class="form-control ng-pristine ng-valid" name="branches" id="cmbBranches"></select>
							</div>
						</div>
					</form>
				
					<table class="table table-striped table-condensed table-bordered" ng-table="tableParams">
						<thead><tr><th>ID</th><th>Sucursal</th><th>Empleado</th><th>Nombre</th><th>Tipo</th><th>Productos</th><th>Valor</th><th>Ponderaci&oacute;n</th><th colspan="2">Acciones</th></tr></thead>
						<tbody><tr ng-repeat="meta in metas | filter:filterText">
							<td>{{meta.metaId}}</td><td>{{meta.branch}}</td><td>{{meta.userEmp}} - {{meta.empName}}</td><td>{{meta.name}}</td><td>{{meta.type}}</td><td>{{meta.products}}</td><td>&gt;= {{meta.valueStr}}</td><td>{{meta.weight}} %</td>
							<td>
								<span>
									<a class="link float-left" href="javascript:void(0);" ng-click="openMetaDialog('edit', meta)">Editar</a>
									&nbsp;
									<a class="link float-left" href="javascript:void(0);" ng-click="delMeta(meta.metaId)">Borrar</a>
								</span>
							</td>
						</tr></tbody>
					</table>
					<div class="wrap-center">
						<ul class="pagination">
							<li ng-class="paginator.hasPrevClass()"><a href="javascript:void(0);" ng-click="paginator.first(); getBranchMetas();">[ &laquo;</a></li>
							<li ng-class="paginator.hasPrevClass()"><a href="javascript:void(0);" ng-click="paginator.prev(); getBranchMetas();">&laquo;</a></li>
							<li ng-class="paginator.itemClass(pg)" ng-repeat="pg in paginator.pages()"><a href="javascript:void(0);" ng-click="paginator.toPage(pg); getBranchMetas();">{{paginator.itemDesc(pg)}}</a></li>
							<li ng-class="paginator.hasNextClass()"><a href="javascript:void(0);" ng-click="paginator.next(); getBrarnchMetas();">&raquo;</a></li>
							<li ng-class="paginator.hasNextClass()"><a href="javascript:void(0);" ng-click="paginator.last(); getBranchMetas();">&raquo; ]</a></li>
						</ul>
					</div>
				</div>
				<div class="panel-footer">
					<input id="metasSearch" name="metasSearch" class="form-control search-box" ng-model="paginator.filter" placeholder="Escriba el texto a buscar y presione ENTER" ng-enter="paginator.toPage(1); getBranchMetas();" />
					<button type="button" class="btn btn-default" ng-click="getBranchMetas()">Refrescar</button>
					<button type="button" class="btn btn-primary" ng-click="openMetaDialog('add', null)">Agregar nueva</button>
				</div>
			</div>
	
			<div class="modal fade" id="dlgAddEditMeta" role="dialog" aria-labelledby="dlgAddEditMeta" aria-hidden="true">
				<div class="modal-dialog">
					<div class="modal-content">
						<form id="addMetaForm" name="addMetaForm" class="form-horizontal" role="form">
							<div class="modal-header">
								<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
								<h4 class="modal-title">Agregar/Editar Meta</h4>
							</div>
							<div class="modal-body">
								<div ng-include="'/Leaderboard/include/modalMessages.html'"></div>
								<div class="form-group">
									<label for="cmbSucursal" class="col-sm-4 control-label">Sucursal</label>
									<div class="col-sm-8">
										<select id="cmbSucursal" name="sucursal" class="form-control" ng-model="branch" ng-options="branch.name for branch in branches | filter:{name:'!TODAS'}" ng-required="!editMetaMode" ng-disabled="loading">
										</select>
									</div>
								</div>
								<div class="form-group">
									<label for="txtUsuario" class="col-sm-4 control-label">Usuario</label>
									<div class="col-sm-8">
										<input id="txtUsuario" name="usuario" class="form-control" type="text" maxlength="150" width="150" 
												ng-model="addMetaData.usrName" autofocus ng-required="!addToAllUsers" ng-disabled="loading || editMetaMode || addToAllUsers" autocomplete="off" autofocus />
										<span><input type="checkbox" ng-model="addToAllUsers" />&nbsp;Aplicar a todos los usuarios de la sucursal</span>
									</div>
								</div>
								<div class="form-group">
									<label for="cmbNombre" class="col-sm-4 control-label">Nombre</label>
									<div class="col-sm-8">
										<select id="cmbNombre" name="nombre" class="form-control" ng-disabled="loading" ng-model="addMetaData.nombre" ng-options="nombr for nombr in nombresMetas" required></select>
									</div>
								</div>
								<div class="form-group">
									<label for="cmbTipo" class="col-sm-4 control-label">Tipo</label>
									<div class="col-sm-8">
										<select id="cmbTipo" name="tipo" class="form-control" ng-model="tipoMeta" ng-options="tipo.name for tipo in tiposMeta" required>
										</select>
									</div>
								</div>
								<div class="form-group">
									<label for="cmbProductos" class="col-sm-4 control-label">Grupo de productos</label>
									<div class="col-sm-8">
										<div class="lst-chx-container form-control">
											<span ng-repeat="prd in productGroups | filter:filterPrd">
												<input type="checkbox" ng-model="prd.selected" ng-disabled="loading" ng-required="!atLeastOneSelected()" /> {{prd.id}} - {{prd.name}}<br/>
											</span>
										</div>
										<div class="filter-select">
											<input id="filterProducts" type="text" class="form-control" ng-model="filterPrd" placeholder="Filtrar grupos de productos" />
											Seleccionar&nbsp;
												<a class="link" href="javascript:void(0);" ng-click="selectAllPrd()">todos</a>&nbsp;
												<a class="link" href="javascript:void(0);" ng-click="selectNonePrd()">ninguno</a>
										</div>
<!-- 										<select id="cmbProductos" name="productos" class="form-control" ng-model="productGroup" ng-options="prd.name for prd in productGroups" required> -->
<!-- 										</select> -->
									</div>
								</div>
								<div class="form-group">
									<label for="calFecha" class="col-sm-4 control-label">Valor</label>
									<div class="col-sm-8 input-append spinner" data-trigger="spinner">
										<input id="txtValor" name="valor" class="form-control" type="text" maxlength="10" width="10" 
												ng-model="addMetaData.valor" required ng-disabled="loading" data-rule="currency" />
									</div>
								</div>
								<div class="form-group">
									<label for="txtPonderacion" class="col-sm-4 control-label">Ponderaci&oacute;n</label>
									<div class="col-sm-8 input-append spinner" data-trigger="spinner">
										<input id="txtPonderacion" name="ponderacion" class="form-control" type="text" maxlength="5" width="5" 
												ng-model="addMetaData.ponderacion" required ng-disabled="loading" data-rule="currency" />
									</div>
								</div>
							</div>
							 <div class="modal-footer">
								<button type="button" class="btn btn-default" data-dismiss="modal">Cancelar</button>
								<button type="submit" class="btn btn-primary" ng-click="saveMeta()" ng-disabled="loading || addMetaForm.$invalid">Guardar cambios</button>
							</div>
						</form>
					</div>
				</div>
			</div>
		</div>
	</div>
</body>
</html>